/**
 * 
 */
package pATT.decisionMaking;

import java.io.File;
import java.util.Observable;
import java.util.Vector;

import pATT.SAVER.DM.DMSAVERManager;
import pATT.SAVER.courseStruct.Contenidos;
import pATT.logger.Message;
import pATT.profile.BayesNetProfileComponent;
import pATT.profile.Profile;

/**
 * @author Ignacio
 *
 */
public class DMSAVER extends DMAlgorithm {
	
	private static final long serialVersionUID = 1L;
	private String courseStructurePath = "";
	private DMSAVERManager manager = null;
	
	
	
	public String getCourseStructurePath() {
		return courseStructurePath;
	}
	
	public void setCourseStructurePath(String courseStructure) {
		this.courseStructurePath = courseStructure;
	}
	public String courseStructurePathTipText(){
		return "Put the course Struct path.";
	}
	
	public DMSAVER() {
		manager = new DMSAVERManager();
	}
	
	@Override
	public String makeDecision(Vector sit, Profile p) {
		String course = obtenerCourseStruct();
		
		if(course.equals("")){
			return null;
		}
		Contenidos contenidos = new Contenidos(course);
		//en el profile esta la red de bayes
		//con el manager se puede ir chequeando la sugerencia
		return manager.checkSuggestion(sit, contenidos, (BayesNetProfileComponent)p.getProfileComponent(0));
	}
	
	@Override
	public boolean hasInstances() {
		return true;
	}
	
	public void update(Observable arg0, Object arg1) {
		
	}
	/**
	 * Retorna el path completo de la estructura del curso, si se elige una erronea se devuelve "".
	 * @return path
	 */
	private String obtenerCourseStruct() {
		if(!getCourseStructurePath().equals("") && !new File(getCourseStructurePath()).isFile()){
			//si la ruta es invalida tira un excepcion
			return "";
		}
		if(getCourseStructurePath().equals("") && !new File(Message.PATH_COURSE_STRUCT_DEFAULT).isFile()){
			//si la ruta por default es invalida tira un excepcion
			return "";
		}
		
		File course = null;
		
		if(getCourseStructurePath().equals("")){
			course = new File(Message.PATH_COURSE_STRUCT_DEFAULT);
		}else{
			course = new File(getCourseStructurePath());
			
		}
		
		return course.getAbsolutePath();
	}
	
}
